package com.hzhr.iot.device.sdk.service;

import com.hzhr.iot.core.constant.Common_ErrorsEnum;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrHttpUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import com.hzhr.iot.device.sdk.constant.Device_ErrorsEnum;
import com.hzhr.iot.device.sdk.model.regulatorDevice_maintenanceCard_item.RegulatorDevice_MaintenanceCard_ItemDeleteModel;
import com.hzhr.iot.device.sdk.model.regulatorDevice_maintenanceCard_item.RegulatorDevice_MaintenanceCard_ItemGetModel;
import com.hzhr.iot.device.sdk.model.regulatorDevice_maintenanceCard_item.RegulatorDevice_MaintenanceCard_ItemModel;
import com.hzhr.iot.device.sdk.model.regulatorDevice_maintenanceCard_item.RegulatorDevice_MaintenanceCard_ItemPostModel;
import com.hzhr.iot.device.sdk.model.regulatorDevice_maintenanceCard_item.RegulatorDevice_MaintenanceCard_ItemPutModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;

@Service
public class Device_RegulatorDevice_MaintenanceCard_ItemService {
    @Autowired
    RestTemplate restTemplate;

    /**
     * 根据调压设备编号和维护卡编号和维护卡选项编号删除调压设备下维护卡的选项 <br/><br/>
     * 简介 : 根据调压设备编号和维护卡编号和维护卡选项编号删除调压设备下维护卡的选项 <br/>
     * 步骤 : <br/>
     * 1. 删除维护卡片选项 : <br/>
     *  根据路径参数regulatorDeviceId、maintenanceCardId和id删除维护卡片选项(DEVICE_MAINTENANCE_CARD_ITEM)deviceMaintenanceItem_1， <br/>
     *  路径参数筛选规则如下： <br/>
     *  (1) deviceMaintenanceItem_1.id = 路径参数id； <br/>
     *  (2) deviceMaintenanceItem_1.cardId = 路径参数maintenanceCardId； <br/>
     *  (3) deviceMaintenanceItem_1.cardExt.deviceId = 路径参数regulatorDeviceId； <br/>
     * 2. 返回信息 : <br/>
     *  根据删除情况组装响应并返回结果 <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/><br/>
     * @param regulatorDeviceId 调压设备编号 <br/><br/>
     * @param maintenanceCardId 维护卡编号 <br/><br/>
     * @param id 维护卡的选项编号 <br/><br/>
     * @throws ServiceException <br/>
     * @see RegulatorDevice_MaintenanceCard_ItemDeleteModel result <br/>
     */ 
    public RegulatorDevice_MaintenanceCard_ItemDeleteModel deleteByRegulatorDeviceIdAndMaintenanceCardIdAndId(Map<String, String> header, Integer regulatorDeviceId, Integer maintenanceCardId, Integer id, Map<String, Object> query) throws ServiceException {
        HttpHeaders headers = new HttpHeaders();
        if (header == null) header = new HashMap<>();
        for (Map.Entry<String, String> entry:
        header.entrySet()) {
            headers.add(entry.getKey(), entry.getValue());
        }
        headers.add("Content-Type", "application/json;charset-utf-8");
        headers.add("accept", "application/json");
        HttpEntity httpEntity = new HttpEntity<>(null, headers);

        Map<String, Object> uriVariables = new HashMap<>();
        uriVariables.put("regulatorDeviceId", regulatorDeviceId);
        uriVariables.put("maintenanceCardId", maintenanceCardId);
        uriVariables.put("id", id);

        try {
            ResponseEntity<RegulatorDevice_MaintenanceCard_ItemDeleteModel> result = restTemplate.exchange("http://device-service/regulator-devices/{regulatorDeviceId}/maintenance-cards/{maintenanceCardId}/items/{id}?" + HzhrHttpUtil.queryMap2url(query), HttpMethod.DELETE, httpEntity, RegulatorDevice_MaintenanceCard_ItemDeleteModel.class, uriVariables);
            return result.getBody();
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            if (e.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_2"));
            }
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
            } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("REGULATORDEVICE_MAINTENANCECARD_ITEMSERVICE_DELETE_BY_REGULATOR_DEVICE_ID_AND_MAINTENANCE_CARD_ID_AND_ID_" + code));
            }
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
             } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("REGULATORDEVICE_MAINTENANCECARD_ITEMSERVICE_DELETE_BY_REGULATOR_DEVICE_ID_AND_MAINTENANCE_CARD_ID_AND_ID_" + code));
             }
        } catch (Throwable e) {
              e.printStackTrace();
              throw e;
        }
    }
    /**
     * 根据调压设备编号和维护卡编号创建该调压设备下维护卡的选项 <br/><br/>
     * 简介 : 根据调压设备编号和维护卡编号创建该调压设备下维护卡的选项 <br/>
     * 步骤 : <br/>
     * 1. 查询设备维护卡片 : <br/>
     *  根据路径参数regulatorDeviceId和maintenanceCardId查询设备卡片(DEVICE_MAINTENANCE_CARD)对象deviceMaintenance_1， <br/>
     *  路径参数筛选规则如下： <br/>
     *  (1) deviceMaintenance_1.deviceId = 路径参数regulatorDeviceId； <br/>
     *  (2) deviceMaintenance_1.id = 路径参数maintenanceCardId； <br/>
     * 如果deviceMaintenance_1不存在，抛出异常201； <br/>
     * 2. 创建维护卡片选项 : <br/>
     *  根据body创建维护卡片选项(DEVICE_MAINTENANCE_CARD_ITEM)对象deviceMaintenanceItem_1， <br/>
     *  额外属性设置规则如下： <br/>
     *  deviceMaintenanceItem_1.cardId = deviceMaintenance_1.id; <br/>
     * 3. 返回信息 : <br/>
     *  根据条件参数查询修改后的对象deviceMaintenanceItem_1的信息生成结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param regulatorDeviceId 调压设备编号 <br/><br/>
     * @param maintenanceCardId 维护卡编号 <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * @see RegulatorDevice_MaintenanceCard_ItemPostModel body <br/>
     * @see RegulatorDevice_MaintenanceCard_ItemGetModel result <br/>
     */ 
    public RegulatorDevice_MaintenanceCard_ItemGetModel postByRegulatorDeviceIdAndMaintenanceCardId(Map<String, String> header, Integer regulatorDeviceId, Integer maintenanceCardId, Map<String, Object> query, RegulatorDevice_MaintenanceCard_ItemPostModel body) throws ServiceException {
        HttpHeaders headers = new HttpHeaders();
        if (header == null) header = new HashMap<>();
        for (Map.Entry<String, String> entry:
        header.entrySet()) {
            headers.add(entry.getKey(), entry.getValue());
        }
        headers.add("Content-Type", "application/json;charset-utf-8");
        headers.add("accept", "application/json");
        HttpEntity httpEntity = new HttpEntity<>(body, headers);

        Map<String, Object> uriVariables = new HashMap<>();
        uriVariables.put("regulatorDeviceId", regulatorDeviceId);
        uriVariables.put("maintenanceCardId", maintenanceCardId);

        try {
            ResponseEntity<RegulatorDevice_MaintenanceCard_ItemGetModel> result = restTemplate.exchange("http://device-service/regulator-devices/{regulatorDeviceId}/maintenance-cards/{maintenanceCardId}/items?" + HzhrHttpUtil.queryMap2url(query), HttpMethod.POST, httpEntity, RegulatorDevice_MaintenanceCard_ItemGetModel.class, uriVariables);
            return result.getBody();
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            if (e.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_2"));
            }
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
            } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("REGULATORDEVICE_MAINTENANCECARD_ITEMSERVICE_POST_BY_REGULATOR_DEVICE_ID_AND_MAINTENANCE_CARD_ID_" + code));
            }
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
             } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("REGULATORDEVICE_MAINTENANCECARD_ITEMSERVICE_POST_BY_REGULATOR_DEVICE_ID_AND_MAINTENANCE_CARD_ID_" + code));
             }
        } catch (Throwable e) {
              e.printStackTrace();
              throw e;
        }
    }
    /**
     * 根据调压设备编号和维护卡编号和维护卡选项编号修改调压设备下维护卡的选项 <br/><br/>
     * 简介 : 根据调压设备编号和维护卡编号和维护卡选项编号修改调压设备下维护卡的选项 <br/>
     * 步骤 : <br/>
     * 1. 查询维护卡片选项： <br/>
     *  根据路径参数id查询维护卡片选项(DEVICE_MAINTENANCE_CARD_ITEM)对象deviceMaintenanceItem_1， <br/>
     *  路径参数筛选规则如下： <br/>
     *  (1) 对象deviceMaintenanceItem_1.id = 路径参数id； <br/>
     *  (2) 对象deviceMaintenanceItem_1.cardId = 路径参数maintenanceCardId； <br/>
     *  (3) 对象deviceMaintenanceItem_1.cardExt.deviceId = 路径参数regulatorDeviceId； <br/>
     *  如果deviceMaintenanceItem_1不存在，抛出异常201； <br/>
     * 2. 修改维护卡片选项 : <br/>
     *  根据body修改deviceMaintenanceItem_1； <br/>
     * 3. 返回信息 : <br/>
     *  根据条件参数查询修改后的对象deviceMaintenanceItem_1的信息生成结果对象并返回； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param regulatorDeviceId 调压设备编号 <br/><br/>
     * @param maintenanceCardId 维护卡编号 <br/><br/>
     * @param id 维护卡的选项编号 <br/><br/>
     * @param body <br/><br/>
     * @throws ServiceException <br/>
     * @see RegulatorDevice_MaintenanceCard_ItemPutModel body <br/>
     * @see RegulatorDevice_MaintenanceCard_ItemGetModel result <br/>
     */ 
    public RegulatorDevice_MaintenanceCard_ItemGetModel putByRegulatorDeviceIdAndMaintenanceCardIdAndId(Map<String, String> header, Integer regulatorDeviceId, Integer maintenanceCardId, Integer id, Map<String, Object> query, RegulatorDevice_MaintenanceCard_ItemPutModel body) throws ServiceException {
        HttpHeaders headers = new HttpHeaders();
        if (header == null) header = new HashMap<>();
        for (Map.Entry<String, String> entry:
        header.entrySet()) {
            headers.add(entry.getKey(), entry.getValue());
        }
        headers.add("Content-Type", "application/json;charset-utf-8");
        headers.add("accept", "application/json");
        HttpEntity httpEntity = new HttpEntity<>(body, headers);

        Map<String, Object> uriVariables = new HashMap<>();
        uriVariables.put("regulatorDeviceId", regulatorDeviceId);
        uriVariables.put("maintenanceCardId", maintenanceCardId);
        uriVariables.put("id", id);

        try {
            ResponseEntity<RegulatorDevice_MaintenanceCard_ItemGetModel> result = restTemplate.exchange("http://device-service/regulator-devices/{regulatorDeviceId}/maintenance-cards/{maintenanceCardId}/items/{id}?" + HzhrHttpUtil.queryMap2url(query), HttpMethod.PUT, httpEntity, RegulatorDevice_MaintenanceCard_ItemGetModel.class, uriVariables);
            return result.getBody();
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            if (e.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_2"));
            }
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
            } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("REGULATORDEVICE_MAINTENANCECARD_ITEMSERVICE_PUT_BY_REGULATOR_DEVICE_ID_AND_MAINTENANCE_CARD_ID_AND_ID_" + code));
            }
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
             } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("REGULATORDEVICE_MAINTENANCECARD_ITEMSERVICE_PUT_BY_REGULATOR_DEVICE_ID_AND_MAINTENANCE_CARD_ID_AND_ID_" + code));
             }
        } catch (Throwable e) {
              e.printStackTrace();
              throw e;
        }
    }
    /**
     * 根据调压设备编号和维护卡编号查询该调压设备下维护卡的选项 <br/><br/>
     * 简介 : 根据调压设备编号和维护卡编号查询该调压设备下维护卡的选项 <br/>
     * 步骤 : <br/>
     * 1. 查询维护卡片选项 : <br/>
     *  根据条件参数以及路径参数regulatorDeviceId和maintenanceCardId查询设备卡片(DEVICE_MAINTENANCE_CARD_ITEM)对象集合deviceMaintenanceCardItemList_1， <br/>
     *  路径参数的筛选规则如下： <br/>
     *  (1) deviceMaintenanceCardItemList_1[i].cardExt.deviceId = 路径参数regulatorDeviceId； <br/>
     *  (2) deviceMaintenanceCardItemList_1[i].cardId = 路径参数maintenanceCardId； <br/>
     *  deviceMaintenanceCardItemList_1的排序规则如下： <br/>
     *  (1) 根据deviceMaintenanceCardItemList_1[i].maintenanceTime进行降序排序； <br/>
     * 2. 返回信息 : <br/>
     *  根据deviceMaintenanceCardItemList_1对象集合及条件参数生成结果对象并返回; <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where sourceRegulaTorTank_maintenanceCard_item.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param regulatorDeviceId 调压设备编号 <br/><br/>
     * @param maintenanceCardId 维护卡编号 <br/><br/>
     * @throws ServiceException <br/>
     * @see RegulatorDevice_MaintenanceCard_ItemGetModel result <br/>
     */ 
    public RegulatorDevice_MaintenanceCard_ItemGetModel getByRegulatorDeviceIdAndMaintenanceCardId(Map<String, String> header, Integer regulatorDeviceId, Integer maintenanceCardId, Map<String, Object> query) throws ServiceException {
        HttpHeaders headers = new HttpHeaders();
        if (header == null) header = new HashMap<>();
        for (Map.Entry<String, String> entry:
        header.entrySet()) {
            headers.add(entry.getKey(), entry.getValue());
        }
        headers.add("Content-Type", "application/json;charset-utf-8");
        headers.add("accept", "application/json");
        HttpEntity httpEntity = new HttpEntity<>(null, headers);

        Map<String, Object> uriVariables = new HashMap<>();
        uriVariables.put("regulatorDeviceId", regulatorDeviceId);
        uriVariables.put("maintenanceCardId", maintenanceCardId);

        try {
            ResponseEntity<RegulatorDevice_MaintenanceCard_ItemGetModel> result = restTemplate.exchange("http://device-service/regulator-devices/{regulatorDeviceId}/maintenance-cards/{maintenanceCardId}/items?" + HzhrHttpUtil.queryMap2url(query), HttpMethod.GET, httpEntity, RegulatorDevice_MaintenanceCard_ItemGetModel.class, uriVariables);
            return result.getBody();
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            if (e.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_2"));
            }
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
            } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("REGULATORDEVICE_MAINTENANCECARD_ITEMSERVICE_GET_BY_REGULATOR_DEVICE_ID_AND_MAINTENANCE_CARD_ID_" + code));
            }
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
             } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("REGULATORDEVICE_MAINTENANCECARD_ITEMSERVICE_GET_BY_REGULATOR_DEVICE_ID_AND_MAINTENANCE_CARD_ID_" + code));
             }
        } catch (Throwable e) {
              e.printStackTrace();
              throw e;
        }
    }
}

